package com.cumt.threeway.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.cumt.threeway.R;
import com.cumt.threeway.table.ActivitiesEntity;
import com.cumt.threeway.view.widget.SelectPicPopupWindow;

/**
 * Created by 胡晶晶 on 2016/5/23.
 */
public class CheckSubmitInfoActivity extends FragmentActivity implements View.OnClickListener {

    private TextView mTvActivityName;
    private TextView mTvUserName;
    private TextView mTvTel;
    private TextView mTvDate;
    private TextView mTvSite;
    private ActivitiesEntity mSingleSubmit;
    SelectPicPopupWindow menuWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shouye_dingdan_xiangqing);
        initView();
    }

    private void initView() {
        mSingleSubmit = (ActivitiesEntity) getIntent().getSerializableExtra("singleSubmit");
        findViewById(R.id.btn_back).setOnClickListener(this);
        findViewById(R.id.btn_dingdan_zixun).setOnClickListener(this);
        mTvActivityName = (TextView) findViewById(R.id.tv_content_name);
        mTvUserName = (TextView) findViewById(R.id.tv_userName);
        mTvTel = (TextView) findViewById(R.id.tv_tel);
        mTvDate = (TextView) findViewById(R.id.tv_date);
        mTvSite = (TextView) findViewById(R.id.tv_site);

        mTvActivityName.setText(mSingleSubmit.getName());
        mTvUserName.setText(mSingleSubmit.getUserName());
        mTvTel.setText(mSingleSubmit.getUserPhone());
        mTvDate.setText(mSingleSubmit.getTime());
        mTvSite.setText(mSingleSubmit.getSite());
    }

    private void goToTelephone() {
        menuWindow = new SelectPicPopupWindow(this, itemsOnClick);
        // 显示窗口
        // 设置layout在PopupWindow中显示的位置
        menuWindow.showAtLocation(this.findViewById(R.id.fcontent),
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }

    // 为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.btn_pick_photo:
                    // 关联电话号码
                    Uri uri = Uri.parse("tel:18052128441");
                    Intent it = new Intent(Intent.ACTION_DIAL, uri);
                    // 启动打电话软件
                    startActivity(it);
                default:
                    break;
            }
        }
    };


    @Override
    public void onClick(View v) {
        if(v == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_dingdan_zixun:
                goToTelephone();
                break;
        }
    }
}
